package com.bkgy.modular.calsidata.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bkgy.component.Consumer;
import com.bkgy.modular.calsidata.dao.Tb_buludatajavamqDao;
import com.bkgy.modular.calsidata.entity.Tb_buludatajavamq;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Component
//@Async
public class Supplementarydata {

    @Resource
    Tb_buludatajavamqDao tb_buludatajavamqDao;

    @Resource
    private Consumer consumer;


    public void saveSiData() {
        try {
            QueryWrapper<Tb_buludatajavamq> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("STATUS", 0);
            queryWrapper.orderByAsc("CREATETIME");
            List<Tb_buludatajavamq> tb_buludatajavamq = tb_buludatajavamqDao.selectList(queryWrapper);
            //System.out.println(jColdPdo653);
            for (Tb_buludatajavamq buludatajavamq : tb_buludatajavamq) {


                //String endtime = ColdPdo653.getPROD_END_TIME();
                //String endtime = "20230103104711";

                String endtimey = buludatajavamq.getYear1();


                String endtimem = buludatajavamq.getMonth1();
                Integer endtimemi = Integer.parseInt(endtimem);
                String endtimed =buludatajavamq.getDay1();
                Integer endtimedi = Integer.parseInt(endtimed);
                String path = "/dscdata/" + endtimey + "/" + endtimemi + "/" + endtimedi + "/";
                String Cmsg = "{\n" +
                        "   \"key\" : {\n" +
                        "      \"endtime\" : \"" + (endtimey  + endtimem  + endtimed) + "\",\n" +
                        "      \"entid\" : \" \",\n" +
                        "      \"extid\" : \"" + buludatajavamq.getExtid() + "\",\n" +
                        "      \"path\" : \"" + path + "\"\n" +
                        "   }\n" +
                        "}";
                String line= buludatajavamq.getLine();
                if(line.equals("C642"))
                {
                    consumer.receiveTopic642(Cmsg);
                    Tb_buludatajavamq buludata = new Tb_buludatajavamq();
                    buludata.setIndocno(buludatajavamq.getIndocno());
                    buludata.setStatus(1.0);
                    int roucout = tb_buludatajavamqDao.updateById(buludata);
                    System.out.println("更新行数为：roucout=" + roucout);
                }


            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public void test_ben() throws SftpException, IOException, JSchException {
        consumer.test();
    }
}
